#!/bin/bash
install_dir="/data/data/com.termux/files/usr/bin"
clone_dir="llama.cpp_armv8l"
string1="cmake安装失败，请重试！"
string2="构建成功！可执行文件在~/llama.cpp_armv8l/build/bin/"
string3="构建失败！请检查错误提示！"
string4="克隆失败，请重试！"
function pkg_install {
	if ! ls "$install_dir" | grep -qw "$1";
	then
		pkg install $1 -y
	fi
}
pkg_install cmake
pkg_install git
if [[ $? -eq 0 ]]; then
	cd ../
	if ! [[ -d "$clone_dir" ]]; then
		git clone git@gitee.com:aiba51/llama.cpp_armv8l.git
	fi
else
	echo "$string1"
	exit 1
fi
if [[ $? -eq 0 ]]; then
	cd llama.cpp_armv8l
	cmake -B build -DBUILD_SHARED_LIBS=OFF
	cmake --build build --config Release
	if [[ $? -eq 0 ]]; then
		echo "$string2"
	else
		echo "$string3"
		rm -rf CMakeCache.txt CMakeFiles/
		exit 1
	fi
else
	echo "$string4"
	exit 1
fi
